package cn.edu.sdjzu.xg.eagle.service;

import cn.edu.sdjzu.xg.eagle.dao.TeacherDao;
import cn.edu.sdjzu.xg.eagle.entity.Teacher;
import cn.edu.sdjzu.xg.eagle.exception.BysjException;
import cn.edu.sdjzu.xg.eagle.inter.TeacherServiceInterface;
import cn.edu.sdjzu.xg.eagle.util.Condition;
import cn.edu.sdjzu.xg.eagle.util.JdbcHelper;
import cn.edu.sdjzu.xg.eagle.util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public class TeacherService implements TeacherServiceInterface {
    private static final TeacherDao teacherDao = TeacherDao.getInstance();
    private static final TeacherService teacherService = new TeacherService();
    private TeacherService() { }

    public static TeacherService getInstance() {
        return teacherService;
    }

    public Collection<Teacher> findAll(List<Condition> conditionList, Pagination pagination) throws SQLException, BysjException {
        //获得连接以便完成可能的事务操作
        Connection connection = JdbcHelper.getConn();
        Collection<Teacher> teachers = teacherDao.findAll(connection, conditionList, pagination);
        JdbcHelper.close(connection);
        return teachers;
    }
}